<?php

class Page {
    
    private $nomPage;
    private $contenu;
    
    function __construct($nomPage=null,$contenu) {
        $this->nomPage = $nomPage;
        $this->contenu = $contenu;
    }
    public function getContenu() {
        return $this->contenu;
    }

    public function setContenu($contenu) {
        $this->contenu = $contenu;
    }
    
    /** getPage($nomPage) **/
    public static function getPage($nomPage) {
        if ($nomPage == null)
            return false;
        $dbInstance = Db::getInstance();
        $sql = 'SELECT * FROM pages
                 WHERE nomPage = "' . $nomPage . '" ';
        $resultat = $dbInstance->query($sql);
        $res = array();
        if ($resultat != null) {
            while ($ligne = $resultat->fetch(PDO::FETCH_OBJ)) {
                $res[] = $ligne;
            }
        }
        $obj = $res[0];
        $p = new Page($nomPage, $obj->contenu);
        return $p;
    }
    public function modifierContenu($contenu=null){
           $dbInstance = Db::getInstance();
           $sql ='UPDATE pages SET ';
           
           
           if ($contenu != null){
                    $this->contenu = $dbInstance->quote($contenu);
                    $sql .='contenu='.$this->contenu;
           }
           
           $sql.=' WHERE nomPage='.$dbInstance->quote($this->nomPage);
           $dbInstance->execute($sql);
       }
    
    

}

?>
